# \src\models\sys_entity_i18n.py
from sqlalchemy import Column, String, DateTime, Boolean, Text, Index
from src.core.ormdb import Base
from src.core import str_utils as strU


class SysEntityI18n(Base):
    __tablename__ = "sys_entity_i18n"

    # 主键
    id = Column(String(36), primary_key=True, default=lambda: strU.generate_id())

    # 业务定位
    api_id = Column(String(36), index=True)
    entity_type = Column(String(30), nullable=False,
                         comment="objects / object_field / object_field_rule / menu / dict / process")
    entity_id = Column(String(36), nullable=False, comment="对应实体主键")
    language = Column(String(10), nullable=False, comment="zh-CN / en-US / fr-FR ...")
    entity_value = Column(Text, nullable=False, comment="翻译后的文本")
    description = Column(Text, comment="翻译备注/上下文提示")
    enabled = Column(Boolean, default=True, comment="是否启用该条翻译")

    # 软删除
    deletion_mark = Column(Boolean, default=False, comment="删除标志，0表示未删除，1表示已删除")
    deletion_reason = Column(String(255), nullable=True, comment="删除原因，记录删除的具体原因")
    deletion_date = Column(DateTime, nullable=True, comment="删除日期，记录删除的时间")
    deletion_by = Column(String(255), nullable=True, comment="删除者，记录删除操作的执行者")

    # 审计
    create_date = Column(DateTime, default=lambda: strU.now(), comment="创建日期，记录创建的时间")
    creator_by = Column(String(255), nullable=True, comment="创建者，记录创建操作的执行者")
    last_updated_date = Column(DateTime, nullable=True, comment="最后更新时间，记录最后更新的时间")
    last_updated_by = Column(String(255), nullable=True, comment="最后更新者，记录最后更新操作的执行者")

    # 联合唯一 + 常用查询索引
    __table_args__ = (
        Index("idx_SysEntityI18n_entity_lang", "entity_type", "entity_id", "language"),
        Index("idx_SysEntityI18n_api_id", "api_id"),
        {"comment": "系统级全局国际化表"},
    )
